package com.xcity.game.npc;

import com.xcity.game.combat.unit.Combatable;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Excel;

/**
 * npc
 * 
 * @author yang.li
 *
 */
@Excel(value = "npc.xlsx", sheet = 0)
public class NpcTemplate extends Template {

	/** 名称 */
	protected String name;

	/** 等级 */
	protected int level;

	/** 头像 */
	protected String icon;

	/** 最小血量 */
	protected int minHp;

	/** 最大血量 */
	protected int maxHp;

	/** 最小攻击力 */
	protected int minAttackPower;

	/** 最大攻击力 */
	protected int maxAttackPower;

	/** 最小法攻 */
	protected int minMagicPower;

	/** 最大法攻 */
	protected int maxMagicPower;
	
	/** 最小物防 */
	protected int minDefense;
	
	/** 最大物防 */
	protected int maxDefense;

	/** 最小法防 */
	protected int minMagicDefense;

	/** 最大法防 */
	protected int maxMagicDefense;
	
	/** 物攻命中 */
	protected float hitRate;
	
	/** 法攻命中 */
	protected float magicHitRate;
	
	/** 闪避 */
	protected float dodge;
	
	/** 暴击 */
	protected float crit;
	
	/** 韧性（免暴） */
	protected float avoidCrit;
	
	/** 抵抗 */
	protected float resist;

	/** 出手速度 */
	protected int attackSpeed;

	/** 每秒能量恢复值 */
	@Deprecated
	protected int mpRecovery;

	/** 掉落组id */
	protected int dropGropId;

	/** skill id */
	protected int[] skillIds;
	
	protected Combatable c;
	
	public NpcTemplate() {
		this.c = new NpcCombatable(this);
	}
	
	public NpcTemplate(NpcTemplate template, float ratio) {
		this.id = template.getId();
		this.name = template.getName();
		this.level = (int) (template.getLevel() * ratio);
		this.icon = template.getIcon();
		this.minHp = (int) (template.getMinHp() * ratio);
		this.maxHp = (int) (template.getMaxHp() * ratio);
		this.minAttackPower = (int) (template.getMinAttackPower() * ratio);
		this.maxAttackPower = (int) (template.getMaxAttackPower() * ratio);
		this.minMagicPower = (int) (template.getMinMagicPower() * ratio);
		this.maxMagicPower = (int) (template.getMaxMagicPower() * ratio);
		this.minDefense = (int) (template.getMinDefense() * ratio);
		this.maxDefense = (int) (template.getMaxDefense() * ratio);
		this.minMagicDefense = (int) (template.getMinMagicDefense() * ratio);
		this.maxMagicDefense = (int) (template.getMaxMagicDefense() * ratio);
		this.hitRate = template.getHitRate() * ratio;
		this.magicHitRate = template.getMagicHitRate() * ratio;
		this.dodge = template.getDodge() * ratio;
		this.crit = template.getCrit() * ratio;
		this.avoidCrit = template.getAvoidCrit() * ratio;
		this.resist = template.getResist() * ratio;
		this.attackSpeed = (int) (template.getAttackSpeed() * ratio);
		this.mpRecovery = (int) (template.getMpRecovery() * ratio);
		this.dropGropId = template.getDropGropId();
		this.skillIds = template.getSkillIds();
		this.c = new NpcCombatable(this);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public int getMinHp() {
		return minHp;
	}

	public void setMinHp(int minHp) {
		this.minHp = minHp;
	}

	public int getMaxHp() {
		return maxHp;
	}

	public void setMaxHp(int maxHp) {
		this.maxHp = maxHp;
	}

	public int getMinAttackPower() {
		return minAttackPower;
	}

	public void setMinAttackPower(int minAttackPower) {
		this.minAttackPower = minAttackPower;
	}

	public int getMaxAttackPower() {
		return maxAttackPower;
	}

	public void setMaxAttackPower(int maxAttackPower) {
		this.maxAttackPower = maxAttackPower;
	}

	public int getMinMagicPower() {
		return minMagicPower;
	}

	public void setMinMagicPower(int minMagicPower) {
		this.minMagicPower = minMagicPower;
	}

	public int getMaxMagicPower() {
		return maxMagicPower;
	}

	public void setMaxMagicPower(int maxMagicPower) {
		this.maxMagicPower = maxMagicPower;
	}

	public int getMinDefense() {
		return minDefense;
	}

	public void setMinDefense(int minDefense) {
		this.minDefense = minDefense;
	}

	public int getMaxDefense() {
		return maxDefense;
	}

	public void setMaxDefense(int maxDefense) {
		this.maxDefense = maxDefense;
	}

	public int getMinMagicDefense() {
		return minMagicDefense;
	}

	public void setMinMagicDefense(int minMagicDefense) {
		this.minMagicDefense = minMagicDefense;
	}

	public int getMaxMagicDefense() {
		return maxMagicDefense;
	}

	public void setMaxMagicDefense(int maxMagicDefense) {
		this.maxMagicDefense = maxMagicDefense;
	}

	public float getHitRate() {
		return hitRate;
	}

	public void setHitRate(float hitRate) {
		this.hitRate = hitRate;
	}

	public float getMagicHitRate() {
		return magicHitRate;
	}

	public void setMagicHitRate(float magicHitRate) {
		this.magicHitRate = magicHitRate;
	}

	public float getDodge() {
		return dodge;
	}

	public void setDodge(float dodge) {
		this.dodge = dodge;
	}

	public float getCrit() {
		return crit;
	}

	public void setCrit(float crit) {
		this.crit = crit;
	}

	public float getAvoidCrit() {
		return avoidCrit;
	}

	public void setAvoidCrit(float avoidCrit) {
		this.avoidCrit = avoidCrit;
	}

	public float getResist() {
		return resist;
	}

	public void setResist(float resist) {
		this.resist = resist;
	}

	public int getAttackSpeed() {
		return attackSpeed;
	}

	public void setAttackSpeed(int attackSpeed) {
		this.attackSpeed = attackSpeed;
	}

	public int getMpRecovery() {
		return mpRecovery;
	}

	public void setMpRecovery(int mpRecovery) {
		this.mpRecovery = mpRecovery;
	}

	public int getDropGropId() {
		return dropGropId;
	}

	public void setDropGropId(int dropGropId) {
		this.dropGropId = dropGropId;
	}

	public int[] getSkillIds() {
		return skillIds;
	}

	public void setSkillIds(int[] skillIds) {
		this.skillIds = skillIds;
	}

	public Combatable toCombatabale() {
		return c;
	}
	
	@Override
	public void validate() throws TemplateException {
		if (getMinAttackPower() > getMaxAttackPower()) {
			throw new TemplateException("npc模板配置错误: id={0,number,#}, minAttackPower={1,number,#}, maxAttackPower={2,number,#}", getId(), getMinAttackPower(), getMaxAttackPower());
		}
		if (getMinMagicPower() > getMaxMagicPower()) {
			throw new TemplateException("npc模板配置错误: id={0,number,#}, minMagicPower={1,number,#}, maxMagicPower={2,number,#}", getId(), getMinMagicPower(), getMaxMagicPower());
		}
		if (getMinDefense() > getMaxDefense()) {
			throw new TemplateException("npc模板配置错误: id={0,number,#}, minDefense={1,number,#}, maxDefense={2,number,#}", getId(), getMinDefense(), getMaxDefense());
		}
		if (getMinMagicDefense() > getMaxMagicDefense()) {
			throw new TemplateException("npc模板配置错误: id={0,number,#}, minMagicDefense={1,number,#}, maxMagicDefense={2,number,#}", getId(), getMinMagicDefense(), getMaxMagicDefense());
		}
		if (getMinHp() > getMaxHp()) {
			throw new TemplateException("npc模板配置错误: id={0,number,#}, minHp={1,number,#}, maxHp={2,number,#}", getId(), getMinHp(), getMaxHp());
		}
	}
}
